<template>
	<view class="container bar">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{data.title}}</block>
		</cu-custom>
		<view class="page-credit">
			<view class="head padding">
				<view class="padding radius shadow bg-gradual-yellow margin-sm">
					<view class="cu-list menu-avatar comment user-card">
						<view class="cu-item">
							<view class="cu-avatar round border" :style="'background-image:url('+data.userinfo.avatar+');'"></view>
							<view class="content">
								<view class="title">
									<view class="text-cut" style="max-width: 80%;">{{data.userinfo.nickname}}</view>
								</view>
								<view class="text-muted text-sm text-content">
									ID:{{data.userinfo.uid}}
								</view>
							</view>
						</view>
					</view>
					<view class="padding margin-bottom text-center">
						<text class="text-xxxl text-black text-bold">￥{{data.userinfo.credit2}}</text>
					</view>
				</view>
			</view>
			<view class="padding text-center" v-if="data.logs.length==0"><text class="text-empty">空空如也</text></view>
			<view class="logs" v-else>
				<view class="cu-list menu sm-border card-menu margin-top-sm">
					<view class="cu-item" v-for="(item, index) in data.logs" :key="index">
						<view class="content padding-tb-sm">
							<view class="text-black text-boldm">
								{{item.remark}}
							</view>
							<view class="text-gray text-sm">
								{{item.createdate}}
							</view>
						</view>
						<view class="action">
							<text class="text-lg text-red" v-if="item.num>0">+</text>
							<text class="text-xl" :class="item.num>0?'text-red':'text-black'">
								{{item.num}}
							</text>
						</view>
					</view>
				</view>
				<uni-load-more class="bg-white" :status="loadmore" :contentText="contentText"></uni-load-more>
			</view>
		</view>
		<view class="cu-bar tabbar" v-if="data.withdraw">
			<view class="action">
				<button @click="naviTo('member/withdraw')" class="cu-btn lg round margin-bottom-xl bg-gradual-red">申请提现</button>
			</view>
		</view>
	</view>
</template>

<script>
	import core from "@/static/core.js"
	
	export default {
		data() {
			return {
				page:1,
				loadmore:'more',
				contentText:{
					"contentdown":"上滑加载更多数据",
					"contentrefresh":"加载中...",
					"contentnomore":"就这么多了~"
				},
				data:{
					title:"收益管理",
					logs:[],
					withdraw:false,
					userinfo:{
						"avatar":"",
						"nickname":"未登录",
						"uid":0,
						"credit1":"----",
						"credit2":"----"
					}
				}
			}
		},
		onLoad() {
			if(core.userinfo.uid<=0) return core.toast('请先登录','login');
			this.data.userinfo = core.userinfo;
		},
		onShow() {
			this.loadLogs(1);
		},
		onPullDownRefresh() {
			this.loadLogs(1);
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if(this.loadmore=='noMore') return;
			this.loadLogs(this.page+1);
		},
		methods:{
			initData(route, data={}, callback=false){
				var that = this;
				core.get(route,function(res){
					if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined'){
						return core.report(res, true);
					}
					that.data = res;
					uni.setNavigationBarTitle({
						title:res.title
					});
					if(callback){
						callback(res);
					}
				},data);
			},
			naviTo(page,data={}){
				return core.navito(page,data);
			},
			unSupport(){
				return core.toast('敬请期待');
			},
			loadLogs(page=1){
				var that = this;
				return core.get('lector/income', function(res){
					if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined') return core.report(res);
					that.page = page;
					if(page==1){
						that.data = res;
					}else{
						that.data.logs = that.data.logs.concat(res.logs);
					}
					that.loadmore = res.logs.length<15 ? 'noMore' : 'more';
				},{page:page});
			}
		}
	}
</script>

<style>
	page{background: #FFFFFF;}
	.head > .bg-gradual-yellow{background-image: url(@/static/images/bg_head_credit.png); background-position: bottom right; background-size: auto 100%; background-repeat: no-repeat;}
	.head .user-card>.cu-item{padding-left: 80upx !important; padding-top: 10upx;}
	.head .user-card>.cu-item .content .title{font-size: 26upx !important; padding-top: 0; line-height: 40upx;}
	.head .user-card>.cu-item .cu-avatar{left: 10upx;}
	.head .user-card>.cu-item .content .title ~ .text-content{transform: scale(0.9); margin-left: -5%; font-size: 24upx; line-height: 20upx;}
	.logs .cu-item > .content{max-width: calc(100% - 100upx); overflow: hidden;}
</style>
